<template>
    <window ref="win" :title="areaTeamName+'-请选择需要剔除统计的班级属性：'">
        <!-- <div class="widget-body"> -->
            <div class="am-form tpl-form-border-form tpl-form-border-br">
                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        <span class="am-text-danger am-margin-right-xs am-text-xs">*</span>产品线：
                    </label>
                    <div class="am-u-sm-9 input-field">
                        <el-select size="small" class="am-u-sm-9" multiple  v-model="formData.productId" placeholder="产品线名称">
                            <el-option
                                v-for="item in products"
                                :key="item.productId"
                                :label="item.name"
                                :value="item.productId">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        <span class="am-text-danger am-margin-right-xs am-text-xs">*</span>年级：
                    </label>
                    <div class="am-u-sm-9 input-field">
                        <el-select size="small" class="am-u-sm-9" multiple  v-model="formData.gradeId" placeholder="年级" @change="handlChange(arguments[0], 'gradeId', grades)">
                            <el-option label="全部年级" value="">全部年级</el-option>
                            <el-option
                                v-for="item in grades"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        <span class="am-text-danger am-margin-right-xs am-text-xs">*</span>科目：
                    </label>
                    <div class="am-u-sm-9 input-field">
                        <el-select size="small" class="am-u-sm-9" multiple  v-model="formData.subjectId" placeholder="科目"  @change="handlChange(arguments[0], 'subjectId', subjects)">
                            <el-option label="全部科目" value="">全部科目</el-option>
                            <el-option
                                v-for="item in subjects"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        <span class="am-text-danger am-margin-right-xs am-text-xs">*</span>班型：
                    </label>
                    <div class="am-u-sm-9 input-field">
                        <el-select size="small" class="am-u-sm-9" multiple  v-model="formData.regLevelId" placeholder="班型"  @change="handlChange(arguments[0], 'regLevelId', regLevels)">
                            <el-option label="全部班型" value="">全部班型</el-option>
                            <el-option
                                v-for="item in regLevels"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
            </div>
            <div>
                <el-button size="small" @click="sure">确认</el-button>
            </div>
        <!-- </div> -->
        
    </window>
</template>

<script>
  import io from '../../lib/io'
  import {regLevels} from '../../lib/global'

  export default{
    data: function () {
        return {
            areaTeamName:'',
            areaTeamId:"",
            products:"",
            regLevels:"",
            formData:{
                productId:[],
                gradeId:[],
                subjectId:[],
                regLevelId:[],
            }
       
        }
    },
    computed: {
      
      grades () {
        return this.$root.config.grades.map(function(item){
            return {value: item.gradeId, label: item.gradeName}
            })
        
      },
      subjects () {
        return this.$root.config.subjects.map(function(item){
            return {value: item.subjectId, label: item.subjectName}
          })
        
      }
    },
    created () {
        this.regLevels = regLevels
        this.loadProductsList()
        

    },
    methods:{
        show:function(){
            this.$refs.win.show( { width : 1000, height: 800 } )
        },
        init(){
            let param = {
               areaTeamId:this.areaTeamId 
            }
            io.post(io.queryfullClassForbidSetting,param,(ret)=>{
                if(ret.success){
                    if(ret.data.productIds){
                        this.formData.productId = ret.data.productIds.split(',')
                    }else{
                       this.formData.productId = []
                    }
                    if(ret.data.gradeIds){
                        this.formData.gradeId = ret.data.gradeIds.split(',')
                    }else{
                        this.formData.gradeId = []
                    }
                    if(ret.data.subjectIds){
                        this.formData.subjectId = ret.data.subjectIds.split(',')
                    }else{
                        this.formData.subjectId = []
                    }
                    if(ret.data.levels){
                        this.formData.regLevelId = ret.data.levels.split(',')
                    }else{
                        this.formData.regLevelId = []
                    }
                }
            })
        },
        handlChange(val, param, list,alia){
            alia = alia || 'value'
            if (val.length > 0 && val[val.length - 1] === '') {
            this.formData[param] = []
                list.map(i => {
                    this.formData[param].push(i[alia])
                })
            }
        },
        loadProductsList:function(){
          io.post(io.apiAdminBaseProductList,{},(ret)=>{
            if(ret.success){
              this.products = ret.data;
            }else{
              this.$alert(ret.desc)
            }
          })
        },
        sure(){
            let formData = {...this.formData}
            let param = {
                productIds:formData.productId.join(','),
                gradeIds:formData.gradeId.join(','),
                subjectIds:formData.subjectId.join(','),
                levels:formData.regLevelId.join(','),
                areaTeamId:this.areaTeamId

            }
            io.post(io.fullClassForbidSetting,param,(ret)=>{
                if(ret.success){
                    this.$refs.win.close()
                    this.$emit('getFullClassRate')
                }else{
                    this.$alert(ret.desc)
                }
            })
            console.log(this.formData)
        }
    }
  }

</script>
